<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String username = request.getParameter("username");
    String password = request.getParameter("password");

    Connection connection= null;
    Statement statement= null;
    ResultSet resultSet =null;

    Class.forName("com.mysql.jdbc.Driver");
    connection = DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone=UTC",
            "root",
            "123456"//登录JDBC链接数据库
    );

    statement = connection.createStatement();
    //从数据库里面取东西对比


    String sql = "select * from tt where name='"+username+"' and password='"+ password + "'";

    ResultSet i = statement.executeQuery(sql);

    if(i.next()){
                      out.println("<script language='javascript'>alert('登录成功！');window.location.href='Zhushouye.jsp';</script>");
                    //response.sendRedirect("Home.jsp");
                }else{
                     out.println("<script language='javascript'>alert('登录失败！');window.location.href='Denglu.jsp';</script>");
                   // response.sendRedirect("Login.jsp");//密码不对返回到登陆

            }

    statement.close();
    connection.close();


%>
</body>
</html>
